package com.lollipop.shiro.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * @Author: J.K
 * @Date: 2021-06-04 16:11
 * @Description: 简单加密
 */
public class SimpleCrypt {
    /**
     * 简单加密
     *
     * @param hashAlgorithmName 加密算法参数:MD5、SHA1等
     * @param credentials       需要加密的字符串
     * @param encryptStr        需要参与加密随机字符串
     * @param hashIterations    散列次数
     * @return
     */
    public static String encryptObject(String hashAlgorithmName, String credentials, String encryptStr, int hashIterations) {
        Object encryptSalt = ByteSource.Util.bytes(encryptStr);
        SimpleHash simpleHash = new SimpleHash(hashAlgorithmName, credentials, encryptSalt, hashIterations);
        String encryptedResult = String.valueOf(simpleHash);
        return encryptedResult;
    }
}
